<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : index.php   FILE_PATH : \\system\index.php
 * ....基本信息设置管理
 *
 * @copyright workflow_system
 * @author workflow Develop Team 
 * @package
 * @subpackage
 * @version Wed Sep 19 14:09:31 CST 2007
 */

require ("../global.inc.php");
class SysBaseInfoManage extends SystemFrameWork{

	/**
	 * 功能导航统计信息对象
	 *
	 * @var obj
	 */
	var $obj_index_statics;
	/**
	 * 权限对象
	 *
	 * @var obj
	 */
	var $obj_system_power;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $obj_validate;

	function main(){
		/**
		 * 创建权限对象
		 */
		if (!is_object($this->obj_system_power)){
			require_once("system_power.class.php");
			$this->obj_system_power = new SystemPowerClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->obj_validate)){
			require_once("commonvalidate.class.php");
			$this->obj_validate = new CommonValidate();
		}
		/**
		 * 语言包
		 */
		$this->getlang("sys_index");

		switch ($this->_input['action']){
			case "out":
				$this->_out();
				break;
			case "main":
				$this->showpage('sys_index');
				break;
			case "guide":
				$this->_guide();
				break;
			case "clear_cache":
				$this->_clear_cache();
				break;
			case "admin_password":
				$this->_admin_password();
				break;
			case "header":
				$this->_header();
				break;
			case "entrance":
				$this->_entrance();
				break;
			case "index_info":
				$this->_index_info();
				break;
			case "help":
				$this->_help();
				break;
			default:
				$this->showpage('sys_index');
				break;
		}

	}
	
	/**
	 * 输出框架页头
	 */
	function _header(){
		/**
		 * 页面输出
		 */
		$this->output('type',$this->_input['type']);
		$this->showpage('sys_header');
	}

	/**
	 * 退出
	 */
	function _out(){
		//记录操作日志
		SystemPowerClass::addSysLog($this->_lang['langSysLogLogout']);
		unset($_SESSION['s_admin']);
		header("location:index.php");
		exit;
	}
	
	/**
	 * 功能导航列表
	 *
	 */
	function _guide(){
		$sys_menu = $this->sysmenu;
		if(is_array($sys_menu)){
			foreach ($sys_menu as $key => $value){
				if(is_array($value['body'])){
					foreach ($value['body'] as $k => $v){
						$sys_menu_is = preg_replace("/~[0-9]*/","",$v['power']);
						switch ($sys_menu_is){
							case "system_baseinfo":
								$sys_menu_baseinfo = $v;
								break;
							case "tools_vote":
								$sys_menu_vote = $v;
								break;
							case "tools_link":
								$sys_menu_link = $v;
								break;
							case "product_category":
								$sys_menu_pcate = $v;
								break;
							case "product_product":
								$sys_menu_product = $v;
								break;
							case "transaction_order":
								$sys_menu_order = $v;
								break;
							case "transaction_complaint":
								$sys_menu_complaint = $v;
								break;
							case "transaction_report":
								$sys_menu_report = $v;
								break;
							case "store_shop":
								$sys_menu_shop = $v;
								break;
							case "statistic_product":
								$sys_menu_stapro = $v;
								break;
							case "statistic_trade":
								$sys_menu_statrade = $v;
								break;
							case "statistic_member":
								$sys_menu_stamember = $v;
								break;
							case "statistic_visit":
								$sys_menu_stavisit = $v;
								break;
							case "member_system_message":
								$sys_menu_sysmessage = $v;
								break;
							case "tools_power_log":
								$sys_menu_syslog = $v;
								break;
							
						}
						
					}
				}

			}
		}
		
		/**
		 * 页面输出
		 */
		$this->output("sys_menu_baseinfo", $sys_menu_baseinfo);
		$this->output("sys_menu_vote", $sys_menu_vote);
		$this->output("sys_menu_link", $sys_menu_link);
		$this->output("sys_menu_pcate", $sys_menu_pcate);
		$this->output("sys_menu_product", $sys_menu_product);
		$this->output("sys_menu_order", $sys_menu_order);
		$this->output("sys_menu_complaint", $sys_menu_complaint);
		$this->output("sys_menu_report", $sys_menu_report);
		$this->output("sys_menu_shop", $sys_menu_shop);
		$this->output("sys_menu_stapro", $sys_menu_stapro);
		$this->output("sys_menu_statrade", $sys_menu_statrade);
		$this->output("sys_menu_stamember", $sys_menu_stamember);
		$this->output("sys_menu_stavisit", $sys_menu_stavisit);
		$this->output("sys_menu_sysmessage", $sys_menu_sysmessage);
		$this->output("sys_menu_threads", $sys_menu_threads);
		$this->output("sys_menu_syslog", $sys_menu_syslog);
		$this->showpage('sys_index.guide');
	}
	
	/**
	 * 取得商城统计信息
	 *
	 * @return unknown
	 */
	function _getShopinfo(){
		/**
		 * 获取商城功能导航统计信息
		 */
		if (!is_object($this->obj_index_statics)) {
			require_once("index.class.php");
			$this->obj_index_statics = new IndexClass();
		}
		$shop = $this->obj_index_statics->getIndexStatics();
		
		/**
		 * 创建访问统计对象
		 */
		if (!is_object($this->obj_statics)){
			/**
			 * 语言包
			 */
			$this->getlang("statics");
			
			require_once("statics.class.php");
			$this->obj_statics = new StaticsClass();
			$array = array('site_url'=>$this->_configinfo[websit][site_url],'datapath'=>$this->_configinfo[stats][datapath],'ippath'=>$this->_configinfo[stats][ippath]);
			$this->obj_statics->StaticsClassStruct($array);
		}
		
		$total_num = $this->obj_statics->getNumSum();
		$shop['visit_ip'] = $total_num['ip'];
		$shop['visit_num'] = $total_num['pv'];


		return $shop;
	}
	
	/**
	 * 取得系统信息
	 *
	 * @return array
	 */
	function _getSysinfo(){
		$sys['version'] = $this->_systeminfo['version']['version'];
		$server_sign = $_SERVER['SERVER_SIGNATURE'];
		$sys['os'] = PHP_OS;
		$sys['php_version'] = PHP_VERSION;

		if (!is_object($this->obj_index_statics)) {
			require_once("index.class.php");
			$this->obj_index_statics = new IndexClass();
		}
		
		$sys['db_version'] = $this->obj_index_statics->getDatabaseVersion();
		
		if(@ini_get('file_uploads')) {
			$sys['upload'] = ini_get('upload_max_filesize');
		} else {
			$sys['upload'] = '<font color="red">' . $this->_lang['langSysINotApprobateUpdata'] . '</font>';
		}

		$sys['db_size'] = $this->obj_index_statics->getDatabaseSize();
		return $sys;
	}

	/**
	 * 当前登录管理员密码修改
	 */
	function _admin_password(){
		
		/**
		 * 页面输出
		 */
		$this->showpage('sys_admin.password');
	}
	
	/**
	 * 清除缓存
	 */
	function _clear_cache(){
		require_once ("baseinfo.class.php");
		$obj_baseinfo = new BaseInfoClass();
		$obj_baseinfo->clear_all_cache('../cache');
		$obj_baseinfo->clear_templates_cache('../templates');
		unset($obj_baseinfo);
		@fopen("../home/index.php");
		$this->redirectPath("error","./html.manage.php?action=list",$this->_lang['langSysICleanCacheOk'],1);
		//Common::outMessage("json",$this->_lang['langSysICleanCacheOk'],1);
	}
	
	/**
	 * 2级菜单入口 type为类别
	 */
	function _entrance(){
//		if ($this->_input['type'] == 'index'){
//			$this->output('sys_menu',$this->sysmenu);
//		}else {
//			if (is_array($this->sysmenu)){
//				foreach ($this->sysmenu as $k => $v){
//					if ($v['power'] == $this->_input['type']){
//						/**
//						 * 页面输出
//						 */
//						$this->output('sys_menu',$v['body']);
//						break;
//					}
//				}
//			}
//		}
		if (is_array($this->sysmenu)){
				foreach ($this->sysmenu as $k => $v){
					if ($v['power'] == $this->_input['type']){
						/**
						 * 页面输出
						 */
						$this->output('sys_menu',$v['body']);
						break;
					}
				}
			}
		//首页信息统计
//		if ($this->_input['type'] == 'index'){
//			$shop_info = $this->_getShopinfo();
//			$this->output("shop_info", $shop_info);
//		}
		$this->output('menu_type',$this->_input['type']);
		$this->showpage('sys_left.menu');
	}
	
	/**
	 * 首页信息
	 */
	function _index_info(){
		$sys_info = $this->_getSysinfo();
		/**
		 * 页面输出
		 */
		$this->output("sys_info", $sys_info);
		$this->showpage('sys_index.content');

	}
}
$baseinfo = new SysBaseInfoManage();
$baseinfo->main();
unset($baseinfo);
?>